package com.fanbai.score.business.http;

import android.content.Context;

import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.common.http.HttpUtils;
import com.fanbai.score.common.http.WebCodes;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.HashMap;

/**
 * Created by acer on 2017/6/18.
 */

public class Busin_RequestNet {


    /**
     *获取活动列表
     * @param ctx
     * @param callBack
     */
    public static void getactivityinfos (final Context ctx, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getactivityinfos");
        String url = WebCodes.HTTP_URL_BUSIN_ACT ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                        callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 领取当日贵人币
     * @param ctx
     * @param callBack
     */
    public static void pickuptodaycoin(final Context ctx, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "pickuptodaycoin");
        String url = WebCodes.HTTP_URL_BUSIN_SCOREA ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }
}
